import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import quad

def test_sufficient_conditions():
    """
    验证函数可积的充分条件
    """
    print("=" * 60)
    print("验证函数可积的充分条件")
    print("=" * 60)
    
    # 1. 连续函数示例
    def continuous_func(x):
        return np.sin(x) + np.cos(x)
    
    # 2. 单调函数示例
    def monotonic_func(x):
        return x**3  # 在任意区间上单调递增
    
    # 3. 有有限个间断点的有界函数示例
    def piecewise_func(x):
        # 在x=0.5处有跳跃间断点
        return np.where(x < 0.5, x**2, 2*x - 0.25)
    
    functions = [
        ("连续函数: sin(x)+cos(x)", continuous_func, "定理2: 连续⇒可积"),
        ("单调函数: x³", monotonic_func, "定理3: 单调⇒可积"),
        ("分段函数: 在x=0.5处有间断点", piecewise_func, "定理4: 有界+有限间断点⇒可积")
    ]
    
    for desc, func, theory in functions:
        try:
            result, error = quad(func, 0, 1)
            print(f"{desc}")
            print(f"{theory} -> 可积，积分值 = {result:.6f}")
            print("-" * 40)
        except Exception as e:
            print(f"{desc}")
            print(f"理论: {theory} -> 实际: 不可积，错误: {e}")
            print("-" * 40)

test_sufficient_conditions()